package com.pengheng.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * mybaits自动填充类
 *
 * @author pengheng
 * @date 2021年8月4日15:57:09
 **/
public class AutoFillObjectHandler implements MetaObjectHandler {

    /**
     * 创建时间
     */
    private final String CREATE_TIME = "createdAt";

    /**
     * 修改时间
     */
    private final String UPDATE_TIME = "updatedAt";

    /**
     * 逻辑删除
     */
//    private final String IS_DELETE = "isDelete";
    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName(CREATE_TIME, LocalDateTime.now(), metaObject);
        setFieldValByName(UPDATE_TIME, LocalDateTime.now(), metaObject);
//        setFieldValByName(IS_DELETE,0,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName(UPDATE_TIME, LocalDateTime.now(), metaObject);
    }
}
